package io.renren.modules.template.controller;

import io.renren.common.utils.FileUtil;
import io.renren.common.utils.R;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * Created by 16091437 on 2017/9/8.
 */
@Controller
public class TemplateController {
    /**test*/
    @RequestMapping(value="/gouploadimg",method= RequestMethod.GET)
    public String goUploadImg(){
        //跳转到template目录下的uploadimg.html
        return "uploadimg";
    }

    //处理文件上传
    @RequestMapping(value="/testuploadimg",method = RequestMethod.POST)
    public @ResponseBody String uploadImg(@RequestParam("file")MultipartFile file,
                                          HttpServletRequest request){
        String contentType = file.getContentType();
        String fileName = file.getOriginalFilename();
        /*System.out.println("fileName-->" + fileName);
        System.out.println("getContentType-->" + contentType);*/
        String filePath = request.getSession().getServletContext().getRealPath("imgupload/");
        try{
            FileUtil.uploadFile(file.getBytes(),filePath,fileName);
        }catch(Exception e){
            //TODO:handle exception
        }
        //近回json
        return "uploadimg success";
    }

    @RequestMapping(value="template/list")
    public R list(){
       return R.ok();    
    }

    @RequestMapping(value="template/setup")
    public R setup(){
       return R.ok();    
    } 
    
    @RequestMapping(value="template/library")
    public R library(){
       return R.ok();    
    }
    
    @RequestMapping(value="template/backup")
    public R backup(){
       return R.ok();    
    }    

    @RequestMapping(value="template/mail")
    public R mail(){
       return R.ok();    
    }            
       
}
